<div id="router-root"></div>
<div class="panel panel-default">
    <div class="panel-heading">
        设备列表
        <div class="btn-group btn-group-sm">
            <button id="add" class="btn btn-primary">添加</button>
            <button id="refresh" class="btn btn-info">刷新</button>
        </div>
    </div>
    <table class="table table-hover">
        <thead>
        <tr>
            <td>ID</td>
            <td>名称</td>
            <td>类型</td>
            <td>状态</td>
            <td>详细信息</td>
            <td>操作</td>
        </tr>
        </thead>
        <tbody>
        {% for r in routers %}
        <tr>
            <td>{{r.id}}</td>
            <td>{{r.name}}</td>
            <td>{{ enum2str(flag, r.flag)}}</td>
            <td>{{ enum2str(state, r.state)}}</td>
            <td>{% raw r.details %}</td>
            <td>
                <div class="btn-group btn-group-sm">
                    <button id="/itpkg/router-{{r.id}}-edit" class="btn btn-success">
                        编辑
                    </button>
                    {% if r.state == state.SUBMIT %}
                    <button id="/itpkg/router-{{r.id}}-init" class="btn btn-danger">
                        初始化
                    </button>
                    {% end %}
                </div>
            </td>
        </tr>
        {% end %}
        </tbody>
    </table>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("button#add").click(function () {
            new Ajax("router-root", "/itpkg/router", "PUT");
        });
        $("button#refresh").click(function () {
            new Ajax("gl_root", "/itpkg/router");
        });
        $("button[id^='/itpkg/router-']").click(function () {
            var ss = $(this).attr("id").split('-');
            if (ss[2] == "edit") {
                new Ajax("router-root", "/itpkg/router", "PUT", {id: ss[1]});
            }
            else if (ss[2] == "init") {
                new Ajax("router-root", "/itpkg/" + ss[1] + "/init");
            }
        });
    });
</script>
<p>&nbsp;</p>